package Servlet.Cart;

import BaseClass.PetInfo;
import DataBase.DataBase;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 检测ID有无重复服务器端
 */
@WebServlet("/UpdateCartInfo")
public class UpdateCartInfoServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取前端传入的数据
        String username = req.getParameter("username");
        String strNum = req.getParameter("num");
        int num = Integer.parseInt(strNum);
        String pid = req.getParameter("pid");
        DataBase.updateCartInfo(username,pid,num);

        List<PetInfo> petInfos = DataBase.getCartInfo(username);
        req.getSession().setAttribute("CartPetInfo",petInfos);

    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}